﻿
namespace FastFood.DataAccess
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using Microsoft.Practices.EnterpriseLibrary.Data;
    using EDOSwit.Entity;
    using FastFood.Business.Entities;
    using FastFood.Business.Entities.Tipos;

    public class VendiblesData : Singleton<VendiblesData>
    {
        #region Attributes

		private readonly Database BaseDatos = DatabaseFactory.CreateDatabase();

		#endregion

        #region Methods

        public IList<Vendibles> ListarByNombre(string nombre)
        {
            var entidades = new List<Vendibles>();
            var comando = BaseDatos.GetStoredProcCommand("SelectVendiblesByNombre");

            BaseDatos.AddInParameter(comando, "nombre", DbType.String, nombre);

            using (var lector = BaseDatos.ExecuteReader(comando))
            {
                while (lector.Read())
                {
                    entidades.Add(new Vendibles
                    {
                        vendibleID = lector.IsDBNull(lector.GetOrdinal("vendibleID")) ? default(short) : lector.GetInt16(lector.GetOrdinal("vendibleID")),
                        nombre = lector.IsDBNull(lector.GetOrdinal("nombre")) ? default(string) : lector.GetString(lector.GetOrdinal("nombre")),
                        precioBruto = lector.IsDBNull(lector.GetOrdinal("precio")) ? default(decimal) : lector.GetDecimal(lector.GetOrdinal("precio")),
                        descripcion = lector.IsDBNull(lector.GetOrdinal("descripcion")) ? default(string) : lector.GetString(lector.GetOrdinal("descripcion")),
                        tipo = (TipoVendible)(lector.GetInt32(lector.GetOrdinal("tipo")))
                    });
                }
            }
            comando.Dispose();
            return entidades;
        }

        #endregion
    }
}
